package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.qf.pojo.City;
import com.qf.pojo.Message;
import com.qf.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/city")
public class CityController {
    @Autowired
    private CityService cityService;

    @GetMapping
    @ResponseBody
    public Message<City> selectAll(int page,int limit){
        PageHelper.startPage(page,limit);
        List<City> cities = cityService.selectAll();
        Message<City> message = new Message<City>();
        message.setData(cities);
        message.setCount(20);
        return message;
    }

    @PostMapping("/del")
    @ResponseBody
    public int del(HttpServletRequest request){
        String cids = request.getParameter("cid");
        int cid = Integer.valueOf(cids);
        int res = cityService.delete(cid);
        return res;
    }
}
